<?php
require_once("inc.public.php");
$id='2';

$atree=array();
	array_push($atree,'1');
	
	$sql = "UPDATE $db->matrix_fifth SET lvl_1=".$id." WHERE uid=".$id;
	mysql_query($sql);	

	while(sizeof($atree)) {

		$node=array_shift($atree);
	 	$nd=0;
		$np=1;

		$strsq1="select id,fifth_upline,fifth_position from $db->users where fifth_upline=".$node." order by fifth_position";
		$rs = mysql_query($strsq1);	

		while ($member = mysql_fetch_assoc($rs)) {	
			array_push($atree,$member["id"]);
			$nd++;
			  
			if($np==$member["fifth_position"]) $np++;
		}

		if($nd<3) {
			$sql = "UPDATE $db->users SET fifth_upline=".$node.",fifth_position=".$np.",fifth_date='".date('Y-m-d')."' WHERE id=".$id;
			mysql_query($sql);
			
			if($np==1){
				$sql = "UPDATE $db->matrix_fifth SET lvl1_1=".$id.",date1_1='".date('Y-m-d')."' WHERE uid=".$node;
				mysql_query($sql);

				$sql = "UPDATE $db->matrix_fifth SET lvl2_1=".$id.",date2_1='".date('Y-m-d')."' WHERE lvl1_1=".$node;
				mysql_query($sql);
				$sql = "UPDATE $db->matrix_fifth SET lvl2_4=".$id.",date2_4='".date('Y-m-d')."' WHERE lvl1_2=".$node;
				mysql_query($sql);
				$sql = "UPDATE $db->matrix_fifth SET lvl2_7=".$id.",date2_7='".date('Y-m-d')."' WHERE lvl1_3=".$node;
				mysql_query($sql);
			}elseif($np==2){
				$sql = "UPDATE $db->matrix_fifth SET lvl1_2=".$id.",date1_2='".date('Y-m-d')."' WHERE uid=".$node;
				mysql_query($sql);

				$sql = "UPDATE $db->matrix_fifth SET lvl2_2=".$id.",date2_2='".date('Y-m-d')."' WHERE lvl1_1=".$node;
				mysql_query($sql);
				$sql = "UPDATE $db->matrix_fifth SET lvl2_5=".$id.",date2_5='".date('Y-m-d')."' WHERE lvl1_2=".$node;
				mysql_query($sql);
				$sql = "UPDATE $db->matrix_fifth SET lvl2_8=".$id.",date2_8='".date('Y-m-d')."' WHERE lvl1_3=".$node;
				mysql_query($sql);
			}elseif($np==3){
				$sql = "UPDATE $db->matrix_fifth SET lvl1_3=".$id.",date1_3='".date('Y-m-d')."' WHERE uid=".$node;
				mysql_query($sql);

				$sql = "UPDATE $db->matrix_fifth SET lvl2_3=".$id.",date2_3='".date('Y-m-d')."' WHERE lvl1_1=".$node;
				mysql_query($sql);
				$sql = "UPDATE $db->matrix_fifth SET lvl2_6=".$id.",date2_6='".date('Y-m-d')."' WHERE lvl1_2=".$node;
				mysql_query($sql);
				$sql = "UPDATE $db->matrix_fifth SET lvl2_9=".$id.",date2_9='".date('Y-m-d')."' WHERE lvl1_3=".$node;
				mysql_query($sql);
			}
			break;
		}	
	}


exit;
		
?>